package org.vectrics.recruiter.web.tags;

import org.vectrics.common.html.*;
import org.apache.ecs.html.Input;
import org.apache.log4j.*;
import org.vectrics.skill.Skill;
import org.vectrics.skill.SkillRating;
import org.vectrics.skill.SkillScoringMethod;


public class SkillGui {
    private static Category log = Category.getInstance(SkillGui.class);

    public static Table makeSkillLevelTable(SkillRating rating, Skill childSkill) {
        Table table = new Table();
        table.setCellSpacing(0);
        table.setCellPadding(0);
        Row row = table.addRow();
        Cell cell = row.addCell();
        cell.addElement(TextHelper.getFont("tinyFont", "No Skill&nbsp;"));
        cell.setVAlign("middle");
        row.addElement(makeLevelRadio(0, rating, childSkill));
        row.addElement(makeLevelRadio(1, rating, childSkill));
        row.addElement(makeLevelRadio(2, rating, childSkill));
        row.addElement(makeLevelRadio(3, rating, childSkill));
        row.addElement(makeLevelRadio(4, rating, childSkill));
        cell = row.addCell();
        cell.setVAlign("middle");
        cell.addElement(TextHelper.getFont("tinyFont", "&nbsp;Expert"));

        return(table);
    }

    private static Cell makeLevelRadio(int level, SkillRating rating, Skill childSkill) {
        Cell cell = new Cell();
        cell.setVAlign("top");
        Input radio = new Input();
        radio.setType(Input.RADIO);
        radio.setName("lvl_" + childSkill.getCode());
        radio.setValue("" + level);
        if (rating != null) {
            if (rating.getLevel() != null) {
                if (level == Integer.parseInt(rating.getLevel()))
                    radio.setChecked(true);
            }
        }
        else if (level == 0) {  // // User has no rating, default display to "none"
            radio.setChecked(true);
        }
        cell.addElement(radio);
        return(cell);
    }


    public static void displayYears(SkillRating rating, Skill skill, Cell cell) {
        Input input = new Input();
        input.setType(Input.text);
        input.setName("yrs_" + skill.getCode());
        if (rating != null) {
            if (rating.getLevel() != null)
            input.setValue(Integer.parseInt(rating.getLevel()));
        }
        input.setStyle("width:80;font-family:verdana,arial,sans serif;font-size=" +
        		"11px");
        cell.addElement(input);
        cell.addElement(TextHelper.getFont("stdFont", " yrs"));
    }


    public static void displayYesNo(SkillRating rating, Skill skill, Cell cell) {
        log.debug("showSkillRating() - making check box for skill");
        Input input = new Input();
        input.setType(Input.CHECKBOX);
        input.setName("yn_" + skill.getCode());

        if (rating != null) {
            if (skill.getScoringMethod().getCode().equals(SkillScoringMethod.SCORING_METHOD_YES_NO)) {
                input.setChecked(rating.hasSkill());
            }
            else {
                input.setChecked(true);
            }
        }
        else {
            input.setChecked(false);
        }
        cell.addElement(input);
        cell.addElement(TextHelper.getFont("subFont", "Has Skill"));
    }


}
